package com.osmino.contacts.list;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.osmino.contacts.R;
import com.osmino.contacts.entity.Contact;

public final class ContactViewHeadItem extends FrameLayout implements OnClickListener{
	
	private TextView tv1, tv2;
	private ImageView badge;
	protected IContactViewController mController;
	
	public ContactViewHeadItem(Context context, IContactViewController controller) {
		super(context);
		LayoutInflater.from(context).inflate(R.layout.contact_view_head_item, this);
		mController = controller;
		tv1 = (TextView) findViewById(R.id.contact_view_head_tv1);
		tv2 = (TextView) findViewById(R.id.contact_view_head_tv2);
		badge =  (ImageView) findViewById(R.id.contact_view_item_badge);
	}
	
	public void setText1(String text){
		if(!TextUtils.isEmpty(text))
			tv1.setText(text);
	}
	
	public void setText2(String text){
		if(!TextUtils.isEmpty(text))
			tv2.setText(text);
	}
	
	@Override
	public void onClick(View v) {
	}
	
	public void setContact(Contact contact){
		Bitmap bmp = contact.getPhoto();
		if(bmp!=null){
			badge.setBackgroundDrawable(new BitmapDrawable(bmp));
		}
		else{
			badge.setBackgroundResource(R.drawable.base_no_avatar_ic);
		}
		setText1(contact.displayName);
		//setText2("blablabla");
	}

}
